﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Web.Security;

namespace PSI
{
    public partial class Default : System.Web.UI.Page
    {
        LINQDataContext bd = new LINQDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            psi_danefirmy nowe = new psi_danefirmy();


            var query = from c in bd.psi_danefirmies
                        where (c.login == TextBox4.Text && c.haslo == TextBox5.Text)
                        select c;

            string login = "";
            string ID = "";
            foreach (var q in query)
            {
                login = q.login;
                ID = q.firma_id.ToString();
            }

            if (login != "")
            {
                FormsAuthentication.Initialize();
                FormsAuthenticationTicket bilet = new FormsAuthenticationTicket(1, TextBox4.Text, DateTime.Now, DateTime.Now.AddMinutes(15), false, FormsAuthentication.FormsCookiePath);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(bilet));
                Response.Cookies.Add(cookie);


                HttpCookie myCookie = new HttpCookie("UserSettings");
                myCookie["idFirmy"] = ID;
                myCookie["login"] = login;
                myCookie.Expires = DateTime.Now.AddMinutes(60);
                Response.Cookies.Add(myCookie);

                Server.Transfer("start.aspx");
            }
            else
            {
                Label4.Visible = true;
            }
        }
    }
}